package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.xmy.cultivate.entity.TrackMarket;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TrackMarketMapper extends BaseMapper<TrackMarket> {

    /**
     * 获取所有子id
     * @param id
     * @return
     */
    @Select("select getTrackMarketChIdAll(${id})")
    public String getTrackMarketChIdAll(@Param("id") Long id);

    /**
     * 导出市场部
     */
    @Select("SELECT track_market.`name` ,getStaffNameForId(track_detail.sourse_id) AS teacher_name,track_detail.school_id_str,track_detail.year_class_id_str,track_detail.class_type_id_str,track_detail.subjects_id_str FROM track_market LEFT JOIN track_detail on track_market.id = track_detail.track_id ${ew.customSqlSegment} ")
    public List<TrackMarket> getTrackMarketDetails(@Param(Constants.WRAPPER) QueryWrapper wrapper);

    /**
     * 导出赛道
     */
    @Select("SELECT track.`name`,track.type,CASE WHEN track_detail.type = 1 THEN getStaffNameForId ( track_detail.sourse_id ) WHEN track_detail.type = 2 THEN getSchoolName ( track_detail.sourse_id ) ELSE NULL END AS teacher_name FROM track LEFT JOIN track_detail on track.id = track_detail.track_id ${ew.customSqlSegment} ")
    public List<TrackMarket> getTrackDetails(@Param(Constants.WRAPPER) QueryWrapper wrapper);


}
